Documentation

Demo - Basketball - Open Dev Kit Documentation

Open Dev Kit Documentation :: Demo - Basketball

Very simple 2D physics-based basketball game utilizing OpenGL and Box2D Physics, where players shoot a ball into a hoop. Holding the spacebar builds power, and releasing it launches the ball. The game consists of two Scenes: the gameplay Scene, where physics and shooting mechanics are handled, and the UI Scene, which displays goals and shots. A power meter displays shot strength, making it more interactive.

How it Works

  • Game Initialization
      The game's main Scene initializes, displaying a basketball hoop and the ball's spawning location. The HUD Scene is also initialized, displaying info like shots thrown, goals scored, and the bar for gauging shooting strength.
  • Player Controls
      Interaction with the game is done by pressing the spacebar. A script located in the Pressed and Released Events of the Controls Keybinds Resource is then executed. Pressing and holding it creates a new ball actor using the CreateBall function, then a Timer (ShootTimer) starts ticking, handling the charging shooting power mechanic each tick. Releasing the spacebar stops the Timer and causes the ball to fling forward by setting the currently spawned ball's Physics Type to "Dynamic" and changing its velocity based on the stored power value of the charging mechanic.
  • UI & Score Tracking
      The UI Scene displays the number of goals scored and total shots taken. Every time the spacebar key is released, the shots variable (specifically BallsThrown) increments by one. Goal points are counted by the ShotChecker actor which is placed in the middle of the net. When ball actors make contact with it, its Collision Actor Started Event increments the Goals variable by one.

If you think anything is missing, please feel free to: submit documentation feedback on this page